<?php $this->load->view('admin/header'); ?>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css"/>
    <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
    <script src="http://code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
    <script>
        $(function() {
            $("#time_start,#time_end").datepicker({
                inline: true,
                dateFormat:'yy-mm-dd'
            });
        });
    </script>
    <div class="main clear">
        <div class="tool">
<!--            <a href="/index.php/admin/article_edit/edit/">添加文章</a>-->
            <form method="get" action="/index.php?d=admin&c=article_list" id="search_article">
                <input name="typeid" type="hidden" value="<?php if(isset($typeid)){echo $typeid;}?>"/>
                <select name="writer">
                    <option value="0">--编辑选择--</option>
                    <?php foreach($admin_arr as $v):?>
                        <option value="<?php echo $v;?>" <?php if($writer == $v){echo 'selected="selected"';}?> ><?php echo $v;?></option>
                    <?php endforeach;?>
                </select>
                <input type="text" value="<?php if(!empty($title)){ echo $title;}else{ echo "请输入文章标题"; }?>" onfocus="if (this.value == '请输入文章标题') this.value = ''" onblur="if (this.value == '') this.value = '请输入文章标题';" class="txt" name="title">
                <span>时间：</span>
                <input type="text" class="txt txtA" name="time_start" id="time_start" value="<?php if(isset($time_start)){echo $time_start;}?>"/>
                <em>～</em>
                <input type="text" class="txt txtA" name="time_end" id="time_end" value="<?php if(isset($time_end)){echo $time_end;}?>"/>
                <a href="javascript:search_article()">文章查找</a>
                <strong>共计：<?php if(!empty($count)){echo $count;}else{echo 0;}?>篇</strong>
                <?php if($is_del!=1):?>
                    <a href="/index.php?d=admin&c=article_list&is_del=1">查看文章回收站</a>
                <?php else:?>
                    <a href="/index.php?d=admin&c=article_list">查看文章列表</a>
                <?php endif;?>

                <script type="text/javascript">
                    function search_article() {
                        $('#search_article').submit();
                    }
                </script>
            </form>
        </div>
        <div class="table02">
            <?php if(!empty($date)):?>
                <script type="text/javascript">
                    function checkall(){
                        //var flag = document.getElementById('ckall').checked;
                        var checkboxs=document.getElementsByName("myck");
                        for (var i=0;i<checkboxs.length;i++) {
                            var e=checkboxs[i];
                            e.checked=!e.checked;
                        }
                    }
                    //批量回收或还原
                    function rec_all(v) {
                        var checkboxs = document.getElementsByName("myck");
                        var ids = '';
                        for (var i = 0; i < checkboxs.length; i++) {
                            var e = checkboxs[i];
                            if (e.checked == true) {
                                ids += ',' + e.value;
                            }
                        }

                        if(ids.length>1){
                            $.get('/index.php?d=admin&c=article_list&m=rec_all&ids=' + ids + '&fl=' + v, function(d) {
                                if(d == 1){
                                    alert('请不要重复添加标签');
                                }else if(d == 2){
                                    alert('失败');
                                }else if(d == 3){
                                    alert('成功');
                                    location.reload();
                                }else{
                                    alert(d);
                                }
                            });
                        }else{
                            alert('请选择要操作的文章');
                        }
                    }
                    //批量添加标签或取消标签
                    function setflag(v,ziduan,caozuo){
                        var checkboxs = document.getElementsByName("myck");
                        var ids = '';
                        for (var i = 0; i < checkboxs.length; i++) {
                            var e = checkboxs[i];
                            if (e.checked == true) {
                                ids += ',' + e.value;
                            }
                        }

                        if(ids.length>1){
                            $.get('/index.php?d=admin&c=article_list&m=setflag&ids=' + ids + '&fl=' + v+'&ziduan='+ziduan+'&caozuo='+caozuo, function(d) {
                                if(d == 1){
                                    alert('请不要重复添加标签');
                                }else if(d == 2){
                                    alert('失败');
                                }else if(d == 3){
                                    alert('成功');
                                    location.reload();
                                }else{
                                    alert(d);
                                }
                            });
                        }else{
                            alert('请选择要添加标签的文章');
                        }
                    }
                </script>
                <div class="table_tool">
                    <input id="ckall" onclick="checkall()" type="checkbox"/>
                    <?php if($is_del!=1):?>
                    <span>全选/反选</span><a href="javascript:rec_all(1)">批量放入回收站</a>
                    <a href="javascript:setflag('a','flag',1)">首页推荐（a）</a>
                    <a href="javascript:setflag('l','flag',1)">首页头条（l）</a>
                    <a href="javascript:setflag('t','mark',1)">页面推荐（t）</a>
                    <?php else:?>
                    <span>全选/反选</span><a href="javascript:rec_all(0)">批量还原</a>
                    <?php endif;?>
                </div>

                <table width="100%" cellspacing="0" cellpadding="0" border="0">
                    <tbody>
                        <tr>
                            <th>选择</th>
                            <th>标题</th>
                            <th>栏目</th>
                            <th>发布时间</th>
                            <th>发布人</th>
                            <th>点击</th>
                            <th>操作</th>
                        </tr>
                        <?php foreach($date as $art):?>
                            <tr>
                                <td><input type="checkbox" name="myck" value="<?php echo $art['id'];?>"/></td>
                                <td><?php echo $art['title']?><span><?php if(isset($art['flag']) && $art['flag']!=''){ echo '属性：('.$art['flag'].')&nbsp;&nbsp;';}?><?php if(isset($art['mark']) && $art['mark']!=''){ echo '标签：('.$art['mark'].')';}?><span></td>
                                <td><?php echo $type_arr[$art['typeid']]['typename'];?></td>
                                <td><?php echo date("Y-m-d H:i:s",$art['pubtime']);?></td>
                                <td><?php echo $art['writer'];?></td>
                                <td><?php echo $art['click'];?></td>
                                <td>
                                    <a href="/index.php?d=admin&c=article_edit&m=edit&id=<?php echo $art['id']?>">编辑</a>|
                                    <?php if($is_del!=1):?>
                                    <a href="/index.php?d=admin&c=article_list&m=rec&id=<?php echo $art['id']?>&flag=1">放入回收站</a>|
                                    <a href="/index.php?c=create&m=create_cont&id=<?php echo $art['id'];?>" target="_blank">生成</a>|
                                    <?php else:?>
                                    <a href="/index.php?d=admin&c=article_list&m=rec&id=<?php echo $art['id']?>">恢复文章</a>|
                                    <?php endif;?>
                                    <a target="_blank" href="/html/<?php echo $type_arr[$art['typeid']]['typedir'].'/'.$art['id']?>.html">查看</a>
                                </td>
                            </tr>
                        <?php endforeach;?>
                        </tbody>
                    </table>
                    <?php if($is_del!=1):?>
                    <div class="table_tool">
                        <span>全选/反选</span><a href="javascript:rec_all(1)">批量放入回收站</a>
                        <a href="javascript:setflag('a','flag',2)">取消首页推荐（a）</a>
                        <a href="javascript:setflag('l','flag',2)">取消首页头条（l）</a>
                        <a href="javascript:setflag('t','mark',2)">取消首页推荐（t）</a>
                    <?php endif;?>
            <?php else:?>
                <div class="table02">
                    <div class="table_tool">&nbsp;&nbsp;&nbsp;你所查找的数据不存在 </div>
                    <div class="pag2"></div>
                </div>
            <?php endif;?>
        </div>
        <div class="pag2"><?php if(!empty($multi)){echo $multi;}?></div>
    </div>
<?php $this->load->view('admin/footer'); ?>